<template>
    <div class="app-container">
        <div style="text-align: center;margin-bottom: 30px">
            火情信息{{ createStatus ? '新增' : '更新' }}
        </div>
        <el-form :model="alarmRecordForm" ref="alarmRecordForm" :rules="alarmRecordFormRules" label-width="120px">
            <el-row :gutter="10">
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="报警名称" prop="title">
                        <el-input v-model="alarmRecordForm.title" placeholder="请输入报警名称" clearable></el-input>
                    </el-form-item>
                </el-col>
              <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                <el-form-item label="上报人" prop="reportPerson">
                  <el-input v-model="alarmRecordForm.reportPerson" placeholder="请输入上报人" clearable></el-input>
                </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="上报时间" prop="reportTime">
                        <el-input v-model="alarmRecordForm.reportTime" placeholder="请输入上报时间" type="datetime" clearable></el-input>
                    </el-form-item>
                </el-col>
              <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                <el-form-item label="关联区域" prop="regionId">
                  <el-input v-model="alarmRecordForm.regionId" placeholder="请输入关联区域" clearable></el-input>
                </el-form-item>
              </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="视频链接" prop="videoUrl">
                        <el-input v-model="alarmRecordForm.videoUrl" placeholder="火情视频链接" clearable></el-input>
                    </el-form-item>
                </el-col>
                <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                    <el-form-item label="报警类型" prop="type" :hidden="feedback">
                        <el-input v-model="alarmRecordForm.type" placeholder="报警类型" clearable></el-input>
                    </el-form-item>
                </el-col>
              <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                <el-form-item label="处理状态" prop="handleStatus" :hidden="feedback">
                  <el-input v-model="alarmRecordForm.handleStatus" placeholder="处理状态" clearable></el-input>
                </el-form-item>
              </el-col>
              <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="8">
                <el-form-item label="处理意见" prop="handleOpinion" :hidden="feedback">
                  <el-input v-model="alarmRecordForm.handleOpinion" placeholder="处理意见" clearable></el-input>
                </el-form-item>
              </el-col>



            </el-row>
        </el-form>
        <div slot="footer" style="text-align: center" class="dialog-footer">
            <el-button @click="cancelFireInfo">取 消</el-button>
            <el-button :loading="addLoading" v-if="createStatus" type="primary" @click="createFireInfo">创 建
            </el-button>
            <el-button :loading="addLoading" v-else type="primary" @click="updateInAlarmRecord">修 改</el-button>
        </div>
    </div>
</template>

<script>
import {
  addInFireInfo,
  getInAlarmRecordVo,
  updateInAlarmRecord, getInAlarmRecordList, addInAlarmRecord
} from "@/api/alarmRecord.js";
import {getInEnterpriseList,getInUserList} from "@/api/enterprise";
import {getBuildingList} from "@/api/building";
import {getInEquipmentMaintenanceVo} from "@/api/equipmentMaintenance";
import {getInEnterpriseDominantList} from "@/api/enterpriseDominant";


export default {
    name: "infoEdit",
    data() {
        return {

          alarmRecordForm:{},
            addLoading: false,
            enterpriseDominantList:[],
            buildingList:[],
            alarmInfoList:[],
            userList:[],
            alarmInfoName:true,
            feedback:true,
            alarmRecordFormRules: {

          },
         /* alarmRecordForm:{
                name: [{required: true, message: '火情名称不能为空', trigger: 'blur'}],
                loaction: [{required: true, message: '详细地址不能为空', trigger: 'blur'}],
                fireUserId: [{required: true, message: '确定用户不能为空', trigger: 'blur'}],
                fireDescription: [{required: true, message: '火情起火描述不能为空', trigger: 'blur'}],
            }*/
        }
    },
    computed: {
        createStatus() {
            return this.$route.query.ucId == null
        },
      enterPriseHidden(){
        let roleCode = this.$store.getters.roleCode;
        return roleCode=="ADMIN"||roleCode=="XT-ADMIN"||roleCode=="ZD-ADMIN"||roleCode=="DD-ADMIN"||roleCode=="JW-ADMIN"||roleCode=="XZ-ADMIN"
      }
    },
    created() {
            // this.getInFireAlarmInfoList()
        this.getBuildingList()
        this.getInEnterpriseDominantList()
        // this.getInUserList()

        if (!this.createStatus) {
           this.feedback=false
            this.getInAlarmRecordVo().then(res=>{
               this.alarmRecordForm=res.data
                this.getInFireAlarmInfoList(res.data.alarmInfoId)
            }).catch(error=>{

            })
        }else{
            console.log(this.$route.query.eId)
            this.alarmRecordForm.equipmentId=this.$route.query.eId
            this.alarmRecordForm.alarmInfoId=this.$route.query.alarmInfoId
            this.getInFireAlarmInfoList(this.$route.query.alarmInfoId)
        }



    },
    methods: {
      getInAlarmRecordVo() {
            return new Promise((resolve, reject) => {
              getInAlarmRecordVo({ucId:this.$route.query.ucId}).then(res=>{
                    resolve(res)
                }).catch(error=>{
                    reject(error)
                })
            })
        },
        getInEquipmentMaintenanceVo(){
            return new Promise((resolve, reject) => {
                getInEquipmentMaintenanceVo({ucId:this.$route.params.ucId}).then(res=>{
                    resolve(res)
                }).catch(error=>{
                    reject(error)
                })
            })
        },
        cancelFireInfo() {
          window.history.back()
        },
        createFireInfo() {
            this.addLoading = true
            this.$refs['alarmRecordForm'].validate(valid => {
                if (valid) {
                  addInAlarmRecord(this.alarmRecordForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "添加报警记录成功"
                        })
                        this.cancelFireInfo()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
      updateInAlarmRecord() {
            this.addLoading = true
            this.$refs['alarmRecordForm'].validate(valid => {
                if (valid) {
                  updateInAlarmRecord(this.alarmRecordForm).then(res => {
                        this.addLoading = false
                        this.$notify.success({
                            title: '成功',
                            message: "更新火情信息成功"
                        })
                        this.cancelFireInfo()
                    }).catch(res => {
                        this.addLoading = false
                        this.$notify.error({
                            title: '失败',
                            message: res.msg
                        })
                    })
                } else {
                    this.addLoading = false
                    console.log("表单验证不通过")
                }
            })
        },
        getInEnterpriseDominantList(){
            getInEnterpriseDominantList({deleted:false}).then(res=>{
                this.enterpriseDominantList = res.data
            }).catch(error=>{

            })
        },
        getBuildingList(){
            getBuildingList({deleted:false}).then(res=>{
                this.buildingList = res.data
            }).catch(error=>{
                alert("获取建筑列表失败")
            })
        },
      getInAlarmRecordList(val){
          getInAlarmRecordList({deleted:false,ucId:val}).then(res=>{
                this.alarmInfoList = res.data
            }).catch(error=>{
                alert("获取火情预警列表失败")
            })
        },
        getInUserList(){
            getInUserList({deleted:false}).then(res=>{
                this.userList = res.data
            }).catch(error=>{
                alert("获取用户列表失败")
            })
        },

    }

}
</script>
